package com.ax.business.prescription.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ax.business.common.util.AjaxRes;
import com.ax.business.common.util.Const;
import com.ax.business.common.util.PageUtils;
import com.ax.business.prescription.domain.BaseAssociator;
import com.ax.business.prescription.domain.PrescriptionAudit;
import com.ax.business.prescription.domain.PrescriptionMast;
import com.ax.business.prescription.service.PrescriptionService;
@Controller
@ResponseBody
public class PrescriptionController {

	@Autowired
	PrescriptionService prescriptionService;
	
	/**
	 * 查看个人处方详情(或全部)
	 * 
	 * @param Map<String, Object> map,request
	 *           
	 * @return PageUtils
	 */
	@RequestMapping("/queryPrescription")
	public AjaxRes queryBaseDoctor(AjaxRes ajaxRes,@RequestParam Map<String, Object> params,HttpServletRequest request){
		try {
			PageUtils prescriptions = prescriptionService.queryPrescriptionSer(params,request);
			ajaxRes.setSucceed(prescriptions, Const.DATA_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 新增处方(模块:(新增(处方审核信息))会员(*会员头像的截取),摄像头视频录制保存)
	 * 
	 * @param PrescriptionMast prescriptionMast,BaseAssociator baseAssociator,PrescriptionAudit prescriptionAudit
	 * String[] parameter
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/insertPrescription")
	public AjaxRes insertPrescription(AjaxRes ajaxRes,HttpServletRequest request,PrescriptionMast prescriptionMast,BaseAssociator baseAssociator,PrescriptionAudit prescriptionAudit,@RequestParam("parameter[]")String[] parameter){
		try {
			this.prescriptionService.insertPrescriptionSer(request,prescriptionMast,baseAssociator,prescriptionAudit,parameter);
			ajaxRes.setSucceed(Const.SAVE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 查看处方审核详情(或全部)
	 * 
	 * @param Map<String, Object> map,request
	 *           
	 * @return PageUtils
	 */
	@RequestMapping("/queryPrescriptionAuditing")
	public AjaxRes queryPrescriptionAuditing(AjaxRes ajaxRes,@RequestParam Map<String, Object> params,HttpServletRequest request){
		try {
			PageUtils prescriptionAuditings = prescriptionService.queryPrescriptionAuditingSer(params,request);
			ajaxRes.setSucceed(prescriptionAuditings, Const.DATA_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 处方审核(模块:药师审核处方(分两种1.本系统医师所开处方2.非本系统医师所开处方))
	 * 
	 * @param PrescriptionMast prescriptionMast,PrescriptionAudit prescriptionAudit,Integer 
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/insertOrUpdateAuditing")
	public AjaxRes insertOrUpdateAuditing(AjaxRes ajaxRes,Integer type,HttpServletRequest request,PrescriptionMast prescriptionMast,PrescriptionAudit prescriptionAudit){
		try {
			this.prescriptionService.insertOrUpdateAuditingSer(type,request,prescriptionMast,prescriptionAudit);
			ajaxRes.setSucceed(Const.OPERATE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}
